<?php
/*
 * Created on 7 Jan, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

/**
 * Load default stylesheet
 * */
function _theme_gloolsgarden_loadDefaultStyleSheet(&$vars) {
    drupal_add_css(path_to_theme() . '/css/960/960.css');
    drupal_add_css(path_to_theme() . '/css/960/test.css');
    drupal_add_css(path_to_theme() . '/css/960/reset.css');
    drupal_add_css(path_to_theme() . '/css/960/fonts.css');
    drupal_add_css(path_to_theme() . '/css/layout.css');
    drupal_add_css(path_to_theme() . '/css/style.css');
}

function _theme_gloolsgarden_loadStylesheetByLayout(&$vars){
	if (!isset($vars['layout'])) {
		return false;
	}
    
    $layout = $vars['layout'];
    
    $layoutStyle = path_to_theme() . '/css/layouts/' . $layout['layout'].'.layout.css';
    
    if (file_exists($layoutStyle)) {
    	drupal_add_css($layoutStyle);
    }
}


/**
 * Set layout
 * 
 * */
function _theme_gloolsgarden_setLayout(&$vars) {
	$layouts = _theme_gloolsgarden_parsePathForLayout($vars);
    
    foreach ($layouts as $layout) {
    	if (file_exists($layout['path'])) {
            $vars['layout'] = $layout;
    	}
    }
}

/**
 * 
 * */
function _theme_gloolsgarden_parsePathForLayout(&$vars){
	$requestPath = request_path();
    $layout = array();
    $basePath = THEME_GG_DIR_TPL.'/layouts';
    
    if (!empty($vars['node'])) {
        
        $nodeLayout = 'node-'.$vars['node']->type;
        $layout[] = array('layout' => $nodeLayout, 'path' => $basePath . '/' . $nodeLayout . '.layout.php');
        $layout[] = array('layout' => 'node', 'path' => $basePath . '/node.layout.php');

    }else if (1===preg_match('/^[a-z]+$/', $requestPath, $channel)) {
        // Top Channel page layout
        $channelLayout = 'channel-'.$channel[0];
        $layout[] = array('layout' => $channelLayout, 'path' => $basePath . '/' . $channelLayout . '.layout.php');
        $layout[] = array('layout' => 'channel', 'path' => $basePath . '/channel.layout.php');
    }else if (true ==$vars['is_front']){
    	$layout[] = array('layout' => 'front', 'path' => $basePath . '/front.layout.php');
    }
    
    $layout[] = array('layout' => 'default', 'path' => $basePath . '/default.layout.php');
    
    return $layout;
}